<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="keyword"  content="Tooi">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
        Python web 之 Django 入门 - Tooi的博客 | Tooi-Blog
        
    </title>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/aircloud.css">
    <link rel="stylesheet" href="/css/gitment.css">
    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
</head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> 瞄准月亮。 </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar ">
            <img src="/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>Tooi6</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/archives">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Python-虚拟环境"><span class="toc-text">Python 虚拟环境</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#为什么使用虚拟环境？"><span class="toc-text">为什么使用虚拟环境？</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#使用"><span class="toc-text">使用</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#概述"><span class="toc-text">概述</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#什么是-Django？"><span class="toc-text">什么是 Django？</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#MTV-与-MVC-的区别？"><span class="toc-text">MTV 与 MVC 的区别？</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Demo"><span class="toc-text">Demo</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#详细教程"><span class="toc-text">详细教程</span></a></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> 瞄准月亮。 </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        Python web 之 Django 入门
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2019-11-14 23:02:06</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/tags/#Python" title="Python">Python</a>
        <span>/</span>
        
        <a class="tag" href="/tags/#Django" title="Django">Django</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content ">
        <h3 id="Python-虚拟环境"><a href="#Python-虚拟环境" class="headerlink" title="Python 虚拟环境"></a>Python 虚拟环境</h3><h4 id="为什么使用虚拟环境？"><a href="#为什么使用虚拟环境？" class="headerlink" title="为什么使用虚拟环境？"></a>为什么使用虚拟环境？</h4><blockquote>
<p>在使用Python语言的时候我们使用pip来安装第三方包，但是由于pip的特性，系统中只能安装每个包的一个版本。但是在实际项目开发中，不同项目可能需要第三方包的不同版本，Python的解决方案就是虚拟环境。顾名思义，虚拟环境就是虚拟出来的一个隔离的Python环境，每个项目都可以有自己的虚拟环境，用pip安装各自的第三方包，不同项目之间也不会存在冲突。</p>
</blockquote>
<h4 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"># 安装 virtualenvwrapper-win  </span><br><span class="line">pip3 install virtualenvwrapper-win  </span><br><span class="line"></span><br><span class="line"># 新建虚拟环境 py3scrapy </span><br><span class="line">mkvirtualenv py3scrapy</span><br><span class="line"></span><br><span class="line"># 进入虚拟环境  </span><br><span class="line">workon py3entest</span><br><span class="line"></span><br><span class="line"># 退出</span><br><span class="line">deactivate</span><br><span class="line"></span><br><span class="line"># 虚拟环境默认放在 C:\%User%\13485\Envs 目录下</span><br></pre></td></tr></table></figure>

<h3 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h3><h4 id="什么是-Django？"><a href="#什么是-Django？" class="headerlink" title="什么是 Django？"></a>什么是 Django？</h4><blockquote>
<p>Django是一个开放源代码的Web应用框架，由Python写成。采用了<strong>MTV</strong>的框架模式，即<strong>模型M，视图V和模版T</strong>。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的，即是CMS（内容管理系统）软件。</p>
</blockquote>
<h4 id="MTV-与-MVC-的区别？"><a href="#MTV-与-MVC-的区别？" class="headerlink" title="MTV 与 MVC 的区别？"></a>MTV 与 MVC 的区别？</h4><ul>
<li><strong>MVC</strong><ul>
<li>Model：数据存取层，负责业务对象和数据库的对象(ORM)的映射</li>
<li>View：视图层，负责与用户的交互(书写逻辑)</li>
<li>Controller：完成用户对模型层和视图层调用,来完成用户的请求</li>
</ul>
</li>
<li><strong>MTV</strong><ul>
<li>Model：数据存取层，负责业务对象与数据库的对象(ORM)的映射</li>
<li>Template：负责如何把页面展示给用户(html)</li>
<li>View：负责业务逻辑，并在适当的时候调用Model和Template</li>
</ul>
</li>
<li><strong>区别：</strong><blockquote>
<p>MVC中的View的目的是<strong>呈现哪一个数据</strong>，而MTV的View的目的是<strong>数据如何呈现</strong> 。<br>也就说MTV把View分成了<strong>视图（展现哪些数据）</strong> 和 <strong>模板（如何展现）</strong> 2个部分，而Contorller这个要素由框架自己来实现了</p>
</blockquote>
</li>
</ul>
<h3 id="Demo"><a href="#Demo" class="headerlink" title="Demo"></a>Demo</h3><blockquote>
<p>参考：<a href="https://blog.csdn.net/niedongri/article/details/81978284" target="_blank" rel="noopener">https://blog.csdn.net/niedongri/article/details/81978284</a></p>
</blockquote>
<h3 id="详细教程"><a href="#详细教程" class="headerlink" title="详细教程"></a>详细教程</h3><blockquote>
<p>W3School：<a href="https://www.w3cschool.cn/django/django-tutorial.html" target="_blank" rel="noopener">https://www.w3cschool.cn/django/django-tutorial.html</a></p>
</blockquote>

        
            <div class="donate-container">
    <div class="donate-button">
        <button id="donate-button">赞赏</button>
    </div>
    <div class="donate-img-container hide" id="donate-img-container">
        <img id="donate-img" src="" data-src="/img/donate.png">
        <p> 感谢鼓励 </p>
    </div>
</div>
        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        

        

        

        
        <li>
            <a target="_blank"  href="https://github.com/Tooi6">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-github"></i>
                            </span>
            </a>
        </li>
        

        

    </ul>
    
    <p>
        <span>/</span>
        
        <span><a href="https://github.com/Tooi6" target="_blank" rel="noopener">Tooi6</a></span>
        <span>/</span>
        
        <span><a href="#">Tooi-Blog</a></span>
        <span>/</span>
        
        <span><a href="#">It helps SEO</a></span>
        <span>/</span>
        
    </p>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>  Theme <a href="https://github.com/aircloud/hexo-theme-aircloud" target="_blank" rel="noopener">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="/js/index.js"></script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




</html>
